package com.ugrow.Study_System.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;


import com.ugrow.Study_System.R;
import com.ugrow.Study_System.adapter.StudentInfoAdapter;
import com.ugrow.Study_System.bean.Student;

import java.util.ArrayList;

public class BaseAdapterActivity extends AppCompatActivity {
    ArrayList<Student> studentAl;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_base_adapter);
        ListView lv = (ListView) findViewById(R.id.act_baseadapter_lv);
        if (studentAl == null) {
            studentAl = new ArrayList<>();
        }
        StudentInfoAdapter adapter = new StudentInfoAdapter(this,studentAl);
        lv.setAdapter(adapter);
        initStudentInfo();
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                String itemName = studentAl.get(i).getName();
                Toast.makeText(BaseAdapterActivity.this, itemName, Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void initStudentInfo() {
        studentAl.add(new Student(1,"貂蝉",18,"女",R.drawable.stu1));
        studentAl.add(new Student(2,"妲己",19,"女",R.drawable.stu2));
        studentAl.add(new Student(3,"王昭君",17,"女",R.drawable.stu3));
        studentAl.add(new Student(4,"兰陵王",18,"男",R.drawable.stu4));
        studentAl.add(new Student(5,"李白",21,"男",R.drawable.stu5));
        studentAl.add(new Student(6,"韩信",22,"男",R.drawable.stu6));
        studentAl.add(new Student(7,"露娜",14,"女",R.drawable.stu7));
        studentAl.add(new Student(8,"达摩",32,"男",R.drawable.stu8));
        studentAl.add(new Student(9,"虞姬",19,"女",R.drawable.stu9));

    }

}
